<template>
  <tr>
    <td><input type="checkbox" v-model="obj.checked" /></td>
    <td>{{ obj.name }}</td>
    <td>{{ obj.price }}</td>
    <td>
      <button @click="add">+</button>
      {{ obj.num }}
      <button @click="del">-</button>
    </td>
    <td>{{ singlePrice }}</td>
    <td><button @click="delFn">删除</button></td>
  </tr>
</template>

<script>
export default {
  props: ["obj"],
  methods: {
    //   抛出事件 点击添加或减时触发对应事件
    add() {
      this.$emit("add");
    },
    del() {
      this.$emit("del");
    },
    // 删除
    delFn() {
      this.$emit("cancel");
    },
  },
  //   created() {
  //     console.log(this.obj instanceof Object);
  //     console.log(this.singlePrice);
  //   },
  computed: {
    singlePrice() {
      return this.obj.num * this.obj.price;
    },
  },
};
</script>

<style>
</style>